Skip to content

Strictness hardening: strict mypy everywhere, wider ruff, strict pytest, pre-commit, CI checks - #5

Merged
nikolaos-paximadakis-eea merged 18 commits into
mainfrom
harden/strictness
Nov 19, 2026
Merged

nikolaos-paximadakis-eea merged 18 commits into
mainfrom
harden/strictness

Conversation

@nikolaos-paximadakis-eea

@nikolaos-paximadakis-eea nikolaos-paximadakis-eea commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Hardens the repo for strictness and correctness. No intended behaviour change except the bug fix below.

Before / after

Check Before After
mypy --strict (package, tests, scripts, tools) 428 errors 0
ruff (as configured) 5 rule families 15 families, 0 findings
pytest -W error 4 failures 485 pass (filterwarnings = error, --strict-markers --strict-config)

Bugs found

  • Fix: TooManyRequestsError.retry_after returned inf/nan for such Retry-After values; it now returns None, like the retry policy (new tests fail without the fix).
  • Test bug: test_upload_passes_delimiter sent a real request to api.reportnet.europa.eu (the schema check wasn't faked). An autouse fixture now fails any test that connects to, sends UDP to, or resolves a non-loopback host (tests/test_no_network_guard.py).
  • Test bug: a fake left uploaded files open.

Other changes

  • Generator: no trailing return None; no None filter for all-required query params (regenerated in separate commits).
  • (A slots=True commit was reverted after review: it changed class-level attribute access on public classes such as RetryPolicy.retries.)
  • .pre-commit-config.yaml (locked ruff + mypy via uv); CI adds ruff format --check, mypy on the whole project, and a generated job that reruns the generators and fails on any diff.

Still non-strict (with reasons in pyproject.toml)

PLR0913, PLC0415, FBT001/002, complexity rules, PT018/SIM117; 27 Any annotations (JSON payloads, forwarded kwargs). TypedDict/Literal on the public API and keyword-only booleans are left for a 0.2.0 decision (they would break callers' type checks).

Local checks

uv run ruff check . && uv run ruff format --check .
uv run mypy
uv run pytest

Reviewed with Codex; the download/export-fallback findings (pre-existing or from 0.1.2) are fixed in a separate PR.

…access

filterwarnings=error exposed two test bugs: test_upload_passes_delimiter sent a
real request to api.reportnet.europa.eu (the pre-upload schema check was not
faked; the library skips the check when the schema is unreadable, so the test
still passed), and a test fake left uploaded files open. An autouse fixture now
fails any test that opens a non-loopback connection.
…d its safe auto-fixes

Ignored with reasons in pyproject.toml: PLR0913 (resource methods mirror endpoints),
PLC0415 (lazy optional pandas), FBT001/002 (public API), PT018/SIM117 (style churn).
The remaining findings are fixed by hand in the following commits.
…-After values

A caller sleeping for retry_after would wait forever on 'inf'. It now returns None
for non-finite values, like the retry policy's own Retry-After parsing.
pathlib instead of os.path/open where equivalent (kept os.path with a coded noqa
where abspath's semantics matter); named constants for magic numbers; explicit
check instead of an assert; keyword-only flag in jobs._wait; coded noqa with a
reason for NaN self-comparisons and the token_scheme default. Complexity rules
(PLR0911/0912/0915) are ignored in config with the reason.
pytest.raises now pins each expected message (PT011); raw match patterns; tuple
parametrize names; pathlib; explicit check instead of an assert in generate_docs;
coded noqa with a reason for fixed-argv subprocess calls, scheme-name 'passwords'
and the backend's typographic quote in a test.
files = package + tests + scripts + tools; warn_unreachable, ignore-without-code,
redundant-expr, truthy-bool, possibly-undefined. Package: typed the frame walk in
caller_stacklevel (drops a type: ignore); coded ignore for a mypy false positive
(bool is numbers.Integral at runtime). Scripts/tools: generic dict args,
Operation.path_fstring as a real method (drops a type: ignore), isinstance
narrowing for Streamlit's upload object. numpy stubs are skipped (3.12 syntax under
python_version 3.11). tests.* has a TEMPORARY untyped-defs override; the rest of
the test errors are fixed next.
Fake API errors carry a real request/response (tests/helpers.api_error) instead
of None; named fakes instead of 'lambda: list.append(...) or value'; calls to
None-returning methods are no longer asserted 'is None' (mypy now guarantees it);
monkeypatch targets by path instead of through easy's private imports; generic
dict arguments.
Test functions return None; pytest fixtures and parametrize arguments are typed;
fakes that only raise are NoReturn; helpers have real signatures (_error takes
json/text explicitly, _event a status). Duck-typed fake clients are cast to
ReportnetClient with a comment, and replaced methods go through monkeypatch.setattr.
…hape)

Same fields, equality, hashing, pickling and replace(); instances no longer have
a __dict__ or weakref support (frozen already forbade new attributes).
…e project, generated-code freshness

.pre-commit-config.yaml runs the locked ruff and mypy through uv. CI adds
'ruff format --check', runs mypy with the configured files, and a 'generated' job
that reruns the model/resource/docs generators and fails on any diff.
Contributor docs list the new commands.
…pback address allowed)

Codex review: the guard only covered socket.connect and rejected loopback
addresses such as 127.0.0.2. Now connect, connect_ex and sendto refuse
non-loopback addresses, getaddrinfo refuses non-local host names, and any
127.0.0.0/8 or ::1 address and *.localhost name counts as local. Covered by
tests/test_no_network_guard.py.
@nikolaos-paximadakis-eea
nikolaos-paximadakis-eea merged commit c9774da into main Nov 19, 2026
6 checks passed
@nikolaos-paximadakis-eea
nikolaos-paximadakis-eea deleted the harden/strictness branch November 19, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant